package emails;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendEmail {
	
	public static void main(String args[]){
		
		try{
		//my ip
		String host="192.168.1.22";
		
		String from="user@test8.com";
		String pwd="user";
		Properties props = System.getProperties();
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", host);
		props.put("mail.smtp.user", from);
		props.put("mail.smtp.password", pwd);
		props.put("mail.smtp.port", "25");
		props.put("mail.smtp.auth", "true");
		
		Session session = Session.getDefaultInstance(props, null);
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress(from));
		
		String[] to = new String[1];
		to[0] = "admin@test8.com";
		
		InternetAddress[] sendTo = new InternetAddress[1];
		for(int j = 0; j<1; j++){
			sendTo[j] = new InternetAddress(to[j]);
		}
		
		message.setRecipients(Message.RecipientType.TO, sendTo);
		
		message.setSubject("Java Mail Test");
		
		message.setText("Test message");
		
		Transport transport = session.getTransport("smtp");
		transport.connect(host, from, pwd);
		transport.sendMessage(message, message.getAllRecipients());
		System.out.println("done");
		transport.close();
		
		
		}
		catch(Exception e){
			System.out.println(e.toString());
		}
	}

}
